chore: Clean up testing framework#2542
Conversation
4fc7e40 to
2aca81c
Compare
aa4b541 to
6d88fb4
Compare
254f7d5 to
903ba78
Compare
There was a problem hiding this comment.
I've left a couple of comments about predicate assertsions that might give us cleaner results from our tests.
| void testVec3(const Vector3 &A, const Vector3 &B, double tolerance) | ||
| { | ||
| EXPECT_NEAR(A.x, B.x, tolerance); | ||
| EXPECT_NEAR(A.y, B.y, tolerance); | ||
| EXPECT_NEAR(A.z, B.z, tolerance); | ||
| } |
There was a problem hiding this comment.
One pain point that I inflicted on myself while doing the parsers work is putting EXPECT statements in a wrapper function. The problem is that, when the test fails, it will just tell you that a line in the wrapper function failed without telling you which line in your actual test called that wrapper function. Returning a predicate assertion, like I explained above, ensure that the test runner reports back the actual place that the line failed.
Co-authored-by: Adam Washington <adam.washington@stfc.ac.uk>
9cef717 to
c8ba80d
Compare
| // Compare TOML values with context, but without insisting on a specific ordering of fields | ||
| void compareToml(std::string location, SerialisedValue toml, SerialisedValue toml2) | ||
| { | ||
| if (toml.is_table()) | ||
| { | ||
| ASSERT_TRUE(toml2.is_table()) << location; | ||
| for (auto &[k, v] : toml.as_table()) | ||
| { | ||
| ASSERT_TRUE(toml2.contains(k)) << location << "." << k << std::endl << "Expected:" << std::endl << toml[k]; | ||
| compareToml(std::format("{}.{}", location, k), v, toml2.at(k)); | ||
| } | ||
| } | ||
| else if (toml.is_array()) | ||
| { | ||
| auto arr = toml.as_array(); | ||
| auto arr2 = toml2.as_array(); | ||
| ASSERT_EQ(arr.size(), arr2.size()) << location << std::endl << "Expected" << std::endl << toml; | ||
| for (int i = 0; i < arr.size(); ++i) | ||
| compareToml(std::format("{}[{}]", location, i), arr[i], arr2[i]); | ||
| } | ||
| else | ||
| { | ||
| EXPECT_EQ(toml, toml2) << location; | ||
| } | ||
| } |
There was a problem hiding this comment.
It's outside the scope of this PR, but this should definitely be reworked to return an assertion predicate.
This is a big clean-up PR of the test classes we had, hopefully making things a little clearer and setting up for follow-on work with
Nodetest fixtures.